<template>
	<view>
		<view class="cardBox">
			<view class="cvsBox">
				<u-row gutter="10">
					<u-col span="2">
						<u-avatar
							:src="goods.avatar || 'https://phantombody.oss-cn-shanghai.aliyuncs.com/Role/Picture/role_default_0.jpg'"
							size="40"></u-avatar>
					</u-col>
					<u-col span="10">
						<view class="u-marle-left name">{{goods.nickname}}</view>
					</u-col>
				</u-row>
			</view>
			<u--image width="100%" height="100%" :src="modelPicUrl" mode="widthFix"></u--image>
			<view class="radioBox">
				<u-row gutter="10">
					<u-col span="3">
						有效时间
					</u-col>
					<u-col span="9">
						<u-radio-group v-model="radiovalue1" placement="row" @change="groupChange">
							<u-radio :customStyle="{marginRight: '10px'}" v-for="(item, index) in radiolist1"
								:key="index" :label="item.name" :name="item.type" @change="radioChange">
							</u-radio>
						</u-radio-group>
					</u-col>
				</u-row>
			</view>
			<view class="sloginBox">
				<view class="sl1">幻体空间·720°发现自己</view>
				<image :src="goods.logo" mode="widthFix"></image>
			</view>
		</view>
		<view class="ubtns2">
			<u-button style="margin: 20rpx 25rpx 0;width: 700rpx;" @click="API_Order()" color="#302C29" shape="circle"
				text="生成分享"></u-button>
		</view>
	</view>
</template>

<script>
	// https://ext.dcloud.net.cn/plugin?id=13840   二位欸吗海报文档地址
	export default {
		data() {
			return {
				type: 1,
				radiovalue1: 1,
				mode: '',
				model_id: '',
				list: [],
				haibaoImg: null,
				modalName: '',
				haibaoShow: false,
				shortUrl: '',
				source: '',
				modelPicUrl: '',
				goods: {
					avatar: '',
					nickname: '',
					logo: 'https://phantombody.oss-cn-shanghai.aliyuncs.com/210d6d8f3a8e9e177598fb9638219aa3009612351ca4ae50646f1fc5203c5e90.png',
				},
				erweimapath: "https://phantombody.oss-cn-shanghai.aliyuncs.com/ROLE/Model/MC202312031617399796/24.jpg",

				radiolist1: [{
						type: 1,
						name: '5分钟',
						disabled: false,
					},
					{
						type: 2,
						name: '7天',
						disabled: false
					},
					{
						type: 3,
						name: '永久',
						disabled: false
					}
				],
			}
		},
		onShow() {
			if (uni.getStorageSync('model_id')) {
				this.model_id = uni.getStorageSync('model_id');
				this.API_user();
				this.API_model();
			}
		},
		methods: {
			API_code() {},
			API_user() {
				var that = this;
				that.ran
					.request('/app-api/member/user/get', {}, 'GET')
					.then(res => {
						console.log(res);
						if (res.code == 200) {
							that.goods.avatar = res.data.avatar;
							that.goods.nickname = res.data.nickname;
							// that.erweimapath = "https://test.huanti3d.com/app-api/system/user-share-qr/get?content=" +item.shortUrl;
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					});
			},
			API_model() {
				var that = this;
				if (that.model_id == 0) {
					uni.showModal({
						title: '提示',
						content: '体验模型不能分享',
						showCancel: false,
						success() {
							uni.reLaunch({
								url: '/pages/3d/index'
							})
						},
					})

				} else {
					that.ran
						.request('/app-api/model/user-space/get?id=' + that.model_id, {}, 'GET')
						.then(res => {
							console.log(res);
							if (res.code == 200) {
								that.mode = res.data;
								that.modelPicUrl = res.data.picUrl;
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								});
							}
						});
				}

			},
			groupChange(n) {
				console.log('groupChange', n);
				this.type = n
			},
			radioChange(n) {
				console.log('radioChange', n);
				this.type = n
			},
			posterSuccess(haibaoImg) {
				this.haibaoImg = haibaoImg;
				this.modalName = 'Image';
			},
			showModal() {
				if (!this.haibaoImg) {
					this.haibaoShow = true;

					uni.showLoading({
						title: '海报生成中...'
					});

				} else {
					this.modalName = 'Image';
				}
			},
			hideModal() {
				this.modalName = null;
			},
			API_Order() {
				var that = this;
				var urls = 'https://test.huanti3d.com/?id=' + that.model_id + '&Authorization=' + uni.getStorageSync(
					'accessToken');
				that.ran
					.request('/app-api/system/user-share-url/create', {
						userModelId: that.model_id,
						shortUrl: urls,
						source: urls,
						modelPicUrl: that.modelPicUrl,
						type: that.type,
					}, 'POST')
					.then(res => {
						console.log(res);
						if (res.code == 200) {
							uni.showToast({
								title: '生成分享成功',
								icon: 'none'
							});
							setTimeout(function() {
								uni.navigateTo({
									url: '/pages/mine/shearList',
								})
							}, 2000)
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #f8f8f8;
	}

	.cardBox {
		background: #fff;
		border-radius: 10rpx;
		margin: 20rpx;
		padding: 30rpx;

		.cvsBox {
			padding: 0 0 30rpx;
		}
	}

	.radioBox {
		padding: 30rpx 0;
	}

	.sloginBox {
		overflow: hidden;

		.sl1 {
			text-align: right;
			font-size: 24rpx;
			color: #666;
		}

		image {
			float: right;
			display: block;
			width: 120rpx;
		}
	}
</style>